package com.companion.companion.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.companion.companion.domain.Admin;
import com.companion.companion.domain.Serverorder;
import com.companion.companion.domain.Vo.AdminDataIO;
import com.companion.companion.domain.Vo.AdminDataVo;
import com.companion.companion.mapper.AdminMapper;
import com.companion.companion.mapper.CaregiverMapper;
import com.companion.companion.mapper.ServerorderMapper;
import com.companion.companion.service.IAdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * 管理员信息Service业务层处理
 * 
 * @author zly
 * @date 2025-05-06
 */
@Service
public class AdminServiceImpl implements IAdminService
{
    @Autowired
    private AdminMapper adminMapper;

    @Autowired
    private ServerorderMapper serverorderMapper;
    @Autowired
    private CaregiverMapper caregiverMapper;

    /**
     * 查询管理员信息
     * 
     * @param adminId 管理员信息主键
     * @return 管理员信息
     */
    @Override
    public Admin selectAdminByAdminId(Long adminId)
    {
        return adminMapper.selectAdminByAdminId(adminId);
    }

    /**
     * 查询管理员信息列表
     * 
     * @param admin 管理员信息
     * @return 管理员信息
     */
    @Override
    public List<Admin> selectAdminList(Admin admin)
    {
        return adminMapper.selectAdminList(admin);
    }

    /**
     * 新增管理员信息
     * 
     * @param admin 管理员信息
     * @return 结果
     */
    @Override
    public int insertAdmin(Admin admin)
    {
        return adminMapper.insertAdmin(admin);
    }

    /**
     * 修改管理员信息
     * 
     * @param admin 管理员信息
     * @return 结果
     */
    @Override
    public int updateAdmin(Admin admin)
    {
        return adminMapper.updateAdmin(admin);
    }

    /**
     * 批量删除管理员信息
     * 
     * @param adminIds 需要删除的管理员信息主键
     * @return 结果
     */
    @Override
    public int deleteAdminByAdminIds(Long[] adminIds)
    {
        return adminMapper.deleteAdminByAdminIds(adminIds);
    }

    /**
     * 删除管理员信息信息
     * 
     * @param adminId 管理员信息主键
     * @return 结果
     */
    @Override
    public int deleteAdminByAdminId(Long adminId)
    {
        return adminMapper.deleteAdminByAdminId(adminId);
    }

    @Override
    public AdminDataVo selectAdminMainDataList(Serverorder serverorder) {
        AdminDataVo vo = new AdminDataVo();
        List<AdminDataIO> ios = new ArrayList<AdminDataIO>();
        Serverorder s = new Serverorder();
        s.setPaymentStatus(4L);
        int i = serverorderMapper.selectServerorderList(s).size();
        vo.setCompletedOrderCount(i);
        vo.setNurseCount(caregiverMapper.selectCaregiverList(null).size());
        vo.setOrderCount(serverorderMapper.selectServerorderList(null).size());
        List<Serverorder> orderList = serverorderMapper.selectServerorderList(serverorder);
        for (Serverorder order : orderList) {
            AdminDataIO io = new AdminDataIO();
            io.setCreatedTime(order.getCreateTime());
            io.setEndTime(order.getEndTime());
            io.setNurseName(order.getCaregiverName());
            io.setOrderId(order.getOrderId());
            io.setOrderStatus(order.getPaymentStatus());
            io.setPatientName(order.getUserName());
            io.setStartTime(order.getStartTime());
            ios.add(io);
        }
        vo.setRows(ios);
        return vo;
    }
}
